#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <limits>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

typedef long long int64;
typedef unsigned long long qword;

typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef vector<pii> vpii;

typedef pair<int64,int64> pii64;
typedef vector<int64> vi64;
typedef vector<vi64> vii64;
typedef vector<vii64> viii64;
typedef vector<pii64> vpii64;

typedef vector<string> vs;

const int dx[]={0,-1,0,1,-1,1, 1,-1};
const int dy[]={1,0,-1,0, 1,1,-1,-1};
const double eps=1e-8;

#define fori(i,a,b) for(int i(a),_b(b);i<=_b;++i)
#define ford(i,a,b) for(int i(a),_b(b);i>=_b;--i)
#define forn(i,n) fori(i,0,n-1)
#define fora(i,a) fori(i,0,a.size()-1)
#define fore(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define all(a) a.begin(),a.end()
#define mp make_pair
#define maximum(a) (*max_element(all(a)))
#define minimum(a) (*min_element(all(a)))
#define findx(a,x) (find(all(a),x)-a.begin())
#define two(X) (1LL<<(X))
#define contain(S,X) (((S)&two(X))!=0)
#define sqr(a) (a)*(a)
#define nmax 1010
#define mmax 200100
#define kmax 11
#define modulo 1000000007
#define maxc 999999999

int n, m;
int calcRow(vs board, int n,int l, int r)
{
	int ans = 0;
	for(int i = l; i<=r; i++)
	{
		ans = ans*10+board[n][i]-48;
	}
	return ans;
	
}

int calcCol(vs board, int m,int l, int r)
{
	int ans = 0;
	for(int j = l; j<=r; j++)
	{
		ans = ans*10+board[j][m]-48;
	}
	return ans;
}
		
int fx[10][10][10][10];
int MaxMatrix(vs board,int i1, int j1, int i2, int j2)
{
	if (i1 > i2 || j1 > j2) return 0;
	if (fx[i1][j1][i2][j2]>-1) return fx[i1][j1][i2][j2];
	fx[i1][j1][i2][j2] = 0;
	for(int i = i1; i <=i2; i++)
	{
		int tmp = calcRow(board,i,j1,j2)+MaxMatrix(board,i1,j1,i-1,j2)+MaxMatrix(board,i+1,j1,i2,j2);
		if (tmp > fx[i1][j1][i2][j2])
			fx[i1][j1][i2][j2] = tmp;
	}
	for(int j = j1; j <=j2; j++)
	{
		int tmp = calcCol(board,j,i1,i2)+MaxMatrix(board,i1,j1,i2,j-1)+MaxMatrix(board,i1,j+1,i2,j2);
		if (tmp > fx[i1][j1][i2][j2])
			fx[i1][j1][i2][j2] = tmp;
	}
	return fx[i1][j1][i2][j2];
}
		
class CutTheNumbers {
public:
	int maximumSum(vector <string> board) {
		
		n = board.size();
		m = board[0].size();
		forn(i1,n) forn(i2,n) forn(j1,m) forn(j2,m) fx[i1][j1][i2][j2] = -1;
		return MaxMatrix(board,0,0,n-1,m-1);
	}
};


// BEGIN KAWIGIEDIT TESTING
// Generated by KawigiEdit-pf 2.3.0
#include <iostream>
#include <string>
#include <vector>
#include <ctime>
#include <cmath>
using namespace std;
bool KawigiEdit_RunTest(int testNum, vector <string> p0, bool hasAnswer, int p1) {
	cout << "Test " << testNum << ": [" << "{";
	for (int i = 0; int(p0.size()) > i; ++i) {
		if (i > 0) {
			cout << ",";
		}
		cout << "\"" << p0[i] << "\"";
	}
	cout << "}";
	cout << "]" << endl;
	CutTheNumbers *obj;
	int answer;
	obj = new CutTheNumbers();
	clock_t startTime = clock();
	answer = obj->maximumSum(p0);
	clock_t endTime = clock();
	delete obj;
	bool res;
	res = true;
	cout << "Time: " << double(endTime - startTime) / CLOCKS_PER_SEC << " seconds" << endl;
	if (hasAnswer) {
		cout << "Desired answer:" << endl;
		cout << "\t" << p1 << endl;
	}
	cout << "Your answer:" << endl;
	cout << "\t" << answer << endl;
	if (hasAnswer) {
		res = answer == p1;
	}
	if (!res) {
		cout << "DOESN'T MATCH!!!!" << endl;
	} else if (double(endTime - startTime) / CLOCKS_PER_SEC >= 2) {
		cout << "FAIL the timeout" << endl;
		res = false;
	} else if (hasAnswer) {
		cout << "Match :-)" << endl;
	} else {
		cout << "OK, but is it right?" << endl;
	}
	cout << "" << endl;
	return res;
}
int main() {
	bool all_right;
	bool disabled;
	bool tests_disabled;
	all_right = true;
	tests_disabled = false;
	
	vector <string> p0;
	int p1;
	
	{
	// ----- test 0 -----
	disabled = false;
	string t0[] = {"123","312"};
			p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
	p1 = 435;
	all_right = (disabled || KawigiEdit_RunTest(0, p0, true, p1) ) && all_right;
	tests_disabled = tests_disabled || disabled;
	// ------------------
	}
	
	{
	// ----- test 1 -----
	disabled = false;
	string t0[] = {"99","11"};
			p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
	p1 = 182;
	all_right = (disabled || KawigiEdit_RunTest(1, p0, true, p1) ) && all_right;
	tests_disabled = tests_disabled || disabled;
	// ------------------
	}
	
	{
	// ----- test 2 -----
	disabled = false;
	string t0[] = {"001","010","111","100"};
			p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
	p1 = 1131;
	all_right = (disabled || KawigiEdit_RunTest(2, p0, true, p1) ) && all_right;
	tests_disabled = tests_disabled || disabled;
	// ------------------
	}
	
	{
	// ----- test 3 -----
	disabled = false;
	string t0[] = {"8"};
			p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
	p1 = 8;
	all_right = (disabled || KawigiEdit_RunTest(3, p0, true, p1) ) && all_right;
	tests_disabled = tests_disabled || disabled;
	// ------------------
	}
	
	if (all_right) {
		if (tests_disabled) {
			cout << "You're a stud (but some test cases were disabled)!" << endl;
		} else {
			cout << "You're a stud (at least on given cases)!" << endl;
		}
	} else {
		cout << "Some of the test cases had errors." << endl;
	}
	return 0;
}
// PROBLEM STATEMENT
// Manao has a board filled with digits represented as vector <string> board. The j-th character of the i-th element of board represents the digit written in cell in row i, column j of the board. The rows are numbered from top to bottom and the columns are numbered from left to right.
// 
// Manao is going to cut it into several non-overlapping fragments. Each of the fragments will be a horizontal or vertical strip containing 1 or more elements. A strip of length N can be interpreted as an N-digit number in base 10 by concatenating the digits on the strip in order. The horizontal strips are read from left to right and the vertical strips are read from top to bottom. The picture below shows a possible cutting of a 4x4 board:
// 
// The sum of the numbers on the fragments in this picture is 493 + 7160 + 23 + 58 + 9 + 45 + 91 = 7879.
// 
// Manao wants to cut the board in such a way that the sum of the numbers on the resulting fragments is the maximum possible. Compute and return this sum.
// 
// DEFINITION
// Class:CutTheNumbers
// Method:maximumSum
// Parameters:vector <string>
// Returns:int
// Method signature:int maximumSum(vector <string> board)
// 
// 
// NOTES
// -The numbers on the cut strips are allowed to have leading zeros. See example #2 for details.
// 
// 
// CONSTRAINTS
// -board will contain between 1 and 4 elements, inclusive.
// -board[0] will be between 1 and 4 characters long, inclusive.
// -Each element of board will be of the same length as board[0].
// -Each character in board will be a decimal digit ('0'-'9').
// 
// 
// EXAMPLES
// 
// 0)
// {"123",
//  "312"}
// 
// Returns: 435
// 
// Manao can cut out both rows in whole, obtaining 123 + 312 = 435. He also could cut the columns one by one for a total of 66, or cut the first column and the residual rows one by one, obtaining 13 + 23 + 12 = 48, or even cut out single elements, but would not get a better sum.
// 
// 1)
// {"99",
//  "11"}
// 
// Returns: 182
// 
// It's better to cut out the whole columns.
// 
// 2)
// {"001",
//  "010",
//  "111",
//  "100"}
// 
// Returns: 1131
// 
// The numbers on the strips may have leading zeros. Cutting the columns in whole, Manao obtains 0011 + 0110 + 1010 = 1131.
// 
// 3)
// {"8"}
// 
// Returns: 8
// 
// 
// 
// END KAWIGIEDIT TESTING
//Powered by KawigiEdit-pf 2.3.0!
